﻿//using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Text;

//using Skynet.BusinessLogic.BusinessComponents;
//using Microsoft.Practices.Unity;
//using Microsoft.WindowsAzure;
//using Microsoft.WindowsAzure.StorageClient;
//using System.Runtime.Serialization;

//namespace Skynet.LibraryModule.Presenter.AddAuthor
//{
//    public  class AddAuthorPresenter  : MasterPresenter<IAddAuthorView>
//    {
//        [Dependency]
//        public Infrastructure.CloudWeb.BusinessServices.IMethodAuditService MethodAuditService { get; set; }

//        [Dependency]
//        public IBCAuthors BCAuthors { get; set; }

//        private CloudQueue CreateQueueClient(string queueName)
//        {
//            var storageAccount = CloudStorageAccount.FromConfigurationSetting("InfrastructureConnectionString");
//            CloudQueueClient queueStorage = storageAccount.CreateCloudQueueClient();
//            CloudQueue queue = queueStorage.GetQueueReference(queueName);
//            bool created = queue.CreateIfNotExist();
//            if (created)
//            {
 
//            }
//            return queue;
//        }


//        private CloudBlobContainer CreateBlobStorage(string containername)
//        {
//            var storageAccount = CloudStorageAccount.FromConfigurationSetting("InfrastructureConnectionString");
//            CloudBlobClient blobStorage = storageAccount.CreateCloudBlobClient();
//            CloudBlobContainer container = blobStorage.GetContainerReference(containername);
//            bool created = container.CreateIfNotExist();            
//            if (created)
//            {
//                var permissions = container.GetPermissions();
//                permissions.PublicAccess = BlobContainerPublicAccessType.Container;
//                container.SetPermissions(permissions); 
//            }
//            return container;
//        }

//        public override void OnViewInitialized()
//        {
            
//        }
//        public override void OnViewLoaded()
//        {
            
//        }

//        public virtual  void Save(string firstname, string lastname, string website,  byte[]  image = null , string imagetype= null)
//        {
//            var item =  new Infrastructure.CloudWeb.Entities.MethodAudit(); 
//            item.Id =  Guid.NewGuid(); 
//            item.Activity =  Guid.NewGuid();
//            item.Application = "Skynetlibrary";
//            item.Created = DateTime.Now;
//            item.Method = "Save";            
//            MethodAuditService.AddMethodAudit(item);

            
            

//            var author = new BusinessLogic.BusinessEntities.Author();  
//            author.Id  =  Guid.NewGuid(); 
//            author.FirstName =  firstname;  
//            author.LastName  =  lastname;  
//            author.WebSite = website;
//            if (image != null)
//            {
//                var blobcontainer = this.CreateBlobStorage("photos");
//                string uniqueBlobName = string.Format("image_{0}.jpg", author.Id.ToString());
//                CloudBlockBlob blob = blobcontainer.GetBlockBlobReference(uniqueBlobName);
//                blob.Properties.ContentType = imagetype;
//                blob.UploadByteArray(image);
//                author.Photo = blob.Uri.ToString();
//            }
//            var dcs = new DataContractSerializer(typeof(BusinessLogic.BusinessEntities.Author));
//            var mem = new System.IO.MemoryStream();
//            dcs.WriteObject(mem, author);
//            var queue = CreateQueueClient("addauthorslibraryqueue");
//            var message = new CloudQueueMessage(mem.ToArray());
//            queue.AddMessage(message);                

//           // this.BCAuthors.Add(author);

            
            
//        }
//    }
//}
